package insertionsort;

import java.util.List;

import _general.ObjectInterface;
import _general.problem.SortAlgorithm;

public class Insertionsort extends SortAlgorithm {
	public Insertionsort(List<ObjectInterface> unsortList) {
		super(unsortList);
		setName("Insertionsort");
	}
	
	public Insertionsort() {	
		setName("Insertionsort");
	}
	
	@Override
	public void start() {
		ObjectInterface next;
		int k = 0;
		for (int i = 1; i < getElementList().size(); i++) {
			next = get(i);
			k = i;
			
			while (k > 0 && get(k-1).getId() > next.getId()) {
				set(k, get(k - 1));
				k--;
			}
			set(k, next);
			//this.print();
		}
	}

}
